﻿var defaultScale=4;//默认缩放级别
var moveLen=30;//控制偏移量
var mapCoefficient=function()//a表示比率
{	
	return { a: defaultScale * 0.25 };
};
var initParameter=function(mapImg,sliderImg,alarmDiv){
	this.mapImgWidth=getId(mapImg).style.width;
	this.mapImgHeight=getId(mapImg).style.height;
}
function initMap(){
	initParameter =new initParameter('mapImg','sliderImg','alarmDiv');
}

function resetToDefaultScale()
{
	defaultScale = 4;
}

function initDivWidth(){
	if(document.uniqueID){ 
		if(parent.hiddenFlag==false){//暂时在IE8中有问题
			mapDx= parseInt(parent.document.body.offsetWidth)-200;
			mapDy=parseInt(parent.document.body.offsetHeight)-45;
		}else{
			mapDx= parseInt(parent.document.body.offsetWidth)-22;
			mapDy=parseInt(parent.document.body.offsetHeight)-45;
		}
     }else{
    	 if(parent.hiddenFlag==false){ 
      		mapDx = parseInt(parent.document.body.offsetWidth)-204;
 			mapDy = parseInt(parent.document.body.offsetHeight)-130;
      	}else{
      		mapDx = parseInt(parent.document.body.offsetWidth)-27;
 			if(parent.screenFlag==false){
 				mapDy = parseInt(parent.document.body.offsetHeight)-120;
 			}else{
 				mapDy = parseInt(parent.document.body.offsetHeight)-40;
 			}
      	}
     }
	//控制主窗体DIV
	getId('mainDiv').style.width=mapDx+"px";
	getId('mainDiv').style.height=mapDy+"px";
	
	if (getId('detailDiv').style.display == 'none') {
		getId('controlPad').style.left = (mapDx - 23) + "px";
	} else {
		getId('controlPad').style.left = (mapDx - 23 - 220) + "px";
	}
	getId('detailDiv').style.left = (mapDx - 220) + "px";
	getId('detailDiv').style.height = mapDy + "px";
}

function initRealTimeInfo(speed){
	var mapDiv = getId("mapDiv");
	if (speed) {
		if (speed > 0 && defaultScale < 80) {
			defaultScale = defaultScale + 1;
		} else if (speed < 0 && defaultScale > 1) {
			defaultScale = defaultScale - 1;
		} else {
			return false;
		}
	}
	getId('mapImg').style.width=(parseInt(initParameter.mapImgWidth)*mapCoefficient().a)+"px";
	getId('mapImg').style.height=(parseInt(initParameter.mapImgHeight)*mapCoefficient().a)+"px";
	mapDiv.style.width=(parseInt(initParameter.mapImgWidth)*mapCoefficient().a)+"px";
	mapDiv.style.height=(parseInt(initParameter.mapImgHeight)*mapCoefficient().a)+"px";
	if(curMap == 1){
		for(var curID in progList)
		{
			if(typeof(progList[curID]) != "object")
				continue;
			
			var initWidth = progList[curID]["w"];
			var initHeight = progList[curID]["h"];
			var scaleX = mapCoefficient().a;
			var scaleY = mapCoefficient().a;
			
			getId(curID).style.left = progList[curID]["x"] * mapCoefficient().a + "px";
			getId(curID).style.top = progList[curID]["y"] * mapCoefficient().a + "px";
			getId(curID).style.width = Math.round(initWidth * mapCoefficient().a) + "px";
			getId(curID).style.height = Math.round(initHeight * mapCoefficient().a) + "px";
			getId(curID).firstChild.setAttribute("transform","scale(" + mapCoefficient().a + ")");
		}
	}
	
	removeInfo();
	for(var i=0;i<readList.length;i+=1){
		var readDiv =getId("read"+readList[i][0]);
		var readRaduis =getId("readRadius"+readList[i][0]);
		if(readDiv){
			readDiv.style.top=(readList[i][4]*mapCoefficient().a)+"px";
			readDiv.style.left=(readList[i][3]*mapCoefficient().a)+"px";

			var radius = readList[i][8]*0.4;
			readRaduis.style.top=(((readList[i][4])-radius)*mapCoefficient().a)+"px";
			readRaduis.style.left=(((readList[i][3])-radius)*mapCoefficient().a)+"px";
			readRaduis.width = radius*2*mapCoefficient().a;
			readRaduis.height = radius*2*mapCoefficient().a;
			var context = readRaduis.getContext('2d');
			context.globalAlpha = 0.5;
			context.clearRect (0, 0,readRaduis.width,readRaduis.height);
			var centerX = readRaduis.width / 2;
			var centerY = readRaduis.height / 2;
			context.beginPath();
			context.arc(centerX, centerY, radius*mapCoefficient().a, 0, 2 * Math.PI, false);
			context.fillStyle = 'yellow';
			context.fill();
			//context.lineWidth = 5;
			context.strokeStyle = '#003300';
			context.stroke();
		}
	}
	for(var i=0;i<areaList.length;i+=1){
		var areaDiv =getId("area"+areaList[i][0]);
		if(areaDiv){
			areaDiv.style.top=(parseInt(areaList[i][4])*mapCoefficient().a)+"px";
			areaDiv.style.left=(parseInt(areaList[i][3])*mapCoefficient().a)+"px";
		}
	}
}
function showPad() {
	if (getId('detailDiv').style.display == 'none') {
		getId('detailDiv').style.display = "block";
		getId('controlPad').style.left = parseInt(getId('controlPad').style.left)
				- parseInt(getId('detailDiv').style.width) + "px";
	} else {
		getId('detailDiv').style.display = "none";
		getId('controlPad').style.left = parseInt(getId('controlPad').style.left)
				+ parseInt(getId('detailDiv').style.width) + "px";
	}
}



